package com.stepforward.me;

import java.util.Calendar;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver {

	private Context mContext; 

	  private Notification mNotification;   
	 private NotificationManager mNotificationManager;    
	 private final static int NOTIFICATION_ID = 0x0001; 
	 
	
	@Override
	public void onReceive(Context arg0, Intent data) {
	Log.d(null, "the time is up,start the alarm...");
	Toast.makeText(arg0, "the time is up,start the alarm...!", Toast.LENGTH_SHORT).show();
	mContext = arg0; 
	
	Bundle extras = data.getExtras();	
	String departure = extras.getString("departure");
	String arrival = extras.getString("arrival");
	String busRoute = extras.getString("route");
	String hour = extras.getString("hour");
	String minute = extras.getString("minute");
	
	String message = busRoute +" is leaving from " + departure +" to "+arrival +" at " + hour +" : " + minute;
	

	 mNotification = new Notification(R.drawable.icon,"This is a notification.",System.currentTimeMillis());    
     //将使用默认的声音来提醒用户    
     mNotification.defaults = Notification.DEFAULT_SOUND;    
     mNotificationManager = (NotificationManager)arg0.getSystemService(arg0.NOTIFICATION_SERVICE);    
      
            Intent mIntent = new Intent(mContext,AlarmRoute.class);    
            //这里需要设置Intent.FLAG_ACTIVITY_NEW_TASK属性    
            mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        
            PendingIntent mContentIntent =PendingIntent.getActivity(mContext,0, mIntent, 0);    
            //这里必需要用setLatestEventInfo(上下文,标题,内容,PendingIntent)不然会报错.    
              
            mNotification.setLatestEventInfo(mContext, "PAAC it", "Your bus is leaving soon~~", mContentIntent);                 
            mNotificationManager.notify(NOTIFICATION_ID, mNotification);  
           
	}


	}